<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="导视设备" prop="kiosk.id"
                :rules="[
                  {required: true, message:'导视设备不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择导视设备"
            labelName = 'kiosk'
            labelValue = 'id'
            :value = "inputForm.kiosk.id"
            :limit="1"
            @getValue='(value) => {inputForm.kiosk.id=value}'
            :columns="[
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            :searchs="[
            {
              prop: 'name',
              label: '名称'
            }
            ]"
            dataListUrl="/smis/kiosk/jfKiosk/list"
            entityBeanName="jfKiosk"
            queryEntityUrl="/smis/kiosk/jfKiosk/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="模块(页面)类型" prop="modularType"
                :rules="[
                 ]">
              <el-input v-model="inputForm.modularType" placeholder="请填写模块(页面)类型"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="人脸的id" prop="face.id"
                :rules="[
                  {required: true, message:'人脸的id不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择人脸的id"
            labelName = 'face'
            labelValue = 'id'
            :value = "inputForm.face.id"
            :limit="1"
            @getValue='(value) => {inputForm.face.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'age',
              label: '年龄'
            },
            {
              prop: 'gender',
              label: '性别'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'age',
              label: '年龄'
            },
            {
              prop: 'gender',
              label: '性别'
            }
            ]"
            dataListUrl="/smis/face/jfKioskFace/list"
            entityBeanName="jfKioskFace"
            queryEntityUrl="/smis/face/jfKioskFace/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="进入时间" prop="enterTime"
                :rules="[
                  {required: true, message:'进入时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.enterTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="离开时间" prop="leaveTime"
                :rules="[
                  {required: true, message:'离开时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.leaveTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="驻足时长(秒)" prop="stayTime"
                :rules="[
                  {required: true, message:'驻足时长(秒)不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.stayTime" placeholder="请填写驻足时长(秒)"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          kiosk: {
            id: ''
          },
          modularType: '',
          face: {
            id: ''
          },
          enterTime: '',
          leaveTime: '',
          stayTime: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建驻足信息`
        } else if (method === 'edit') {
          this.title = '修改驻足信息'
        } else if (method === 'view') {
          this.title = '查看驻足信息'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/smis/face/jfKioskFaceTrack/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.jfKioskFaceTrack)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/smis/face/jfKioskFaceTrack/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>